/**
 * @Author: zc
 * @Date: 2019-11-16 19:04:22
 * @LastEditors: zc
 * @LastEditTime: 2020-08-03 16:33:32
*/

const proxy = require('http-proxy-middleware')
const PREHOST = process.env.REACT_APP_PREHOST || ''
module.exports = function(app) {
  if(process.env.NODE_ENV === 'development') {
    app.use(
      proxy('/mock', {
        target: `http://localhost:${process.env.REACT_APP_MOCKPORT}/`,
        changeOrigin: true,
        secure: false,
        pathRewrite: {
          '^/mock': ''
        }
      })
    )
    app.use(
      proxy('/api', {
        target: process.env.REACT_APP_APITYPE === 'pre' && PREHOST !== '' ? PREHOST : process.env.REACT_APP_HOST,
        changeOrigin: true,
        secure: false,
        pathRewrite: {
          '^/api': ''
        }
      })
    ) 
  }
}